export default {
  beforeMount(el, binding) {
    el.clickOutsideEvent = (event) => {
      // 判断点击是否发生在el之外
      if (!(el === event.target || el.contains(event.target))) {
        // 如果是，执行绑定的方法
        el.handler = function (event) {
          let  input = event.target;
          input.value = input.value
          .replace(/[^-|0-9.]/g, "")
          .replace(/(\..*)\./g, "$1");
            // /(^[\-0-9][0-9]*(\.[0-9]+)?)$/   .replace(/[^0-9.]/g, "")            .replace(/(\..*)\./g, "$1");
        };
        el.addEventListener("input", el.handler);
      }
    };
    // 添加事件监听
    document.addEventListener("click", el.clickOutsideEvent);
  },
  unmounted(el) {
    // 移除事件监听
    document.removeEventListener("click", el.clickOutsideEvent);
  },
};
